package com.cn.wanxi.servlet.back.upload;

import com.cn.wanxi.model.DataField;
import com.cn.wanxi.util.DataEncoding;
import com.cn.wanxi.util.Upload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/upload")
public class UploadServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataEncoding.setJsonContentType(resp);
        DataEncoding.setCharacterEncoding(req,resp);
        Upload.FileUpload(req, DataField.outPath, DataField.url);//暂时存放在out文件夹
        String photo = DataEncoding.CastEncoding((String) req.getAttribute("photo"));
        System.out.println(photo);
        resp.getWriter().print(photo);
    }
}
